package com.cn.gmall.product.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cn.gmall.model.product.BaseCategoryTrademark;
import com.cn.gmall.model.product.BaseTrademark;
import com.cn.gmall.product.mapper.BaseTrademarkMapper;
import com.cn.gmall.product.service.BaseTrademarkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class BaseTrademarkServiceImpl extends ServiceImpl<BaseTrademarkMapper,BaseTrademark> implements BaseTrademarkService {
    @Autowired
    private BaseTrademarkMapper baseTrademarkMapper;

    /**
     *  保存 baseTrademark
     * @param baseTrademark
     */

    @Override
    public void saveBaseTrademark(BaseTrademark baseTrademark) {
        baseTrademarkMapper.insert(baseTrademark);
    }

    /***
     * 根据品牌Id 获取品牌对象
     * @param id
     * @return
     */
    @Override
    public BaseTrademark getBaseTradeMarkById(Long id) {
        BaseTrademark baseTrademark = baseTrademarkMapper.selectById(id);
        if (baseTrademark != null) {
            return baseTrademark;
        }else {
            return null;
        }
    }

    /**
     * 品牌 分页列表
     * @param tra page 对象 封装了pageNum 和 pageSize
     * @return
     */
    @Override
    public IPage<BaseTrademark> baseTrademarkPage(Page<BaseTrademark> tra) {
        LambdaQueryWrapper<BaseTrademark> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.orderByAsc(BaseTrademark::getId);

        return  baseTrademarkMapper.selectPage(tra,queryWrapper );
    }
}
